package gameEngine.agents;

import java.util.ArrayList;
import gameEngine.agents.Logger.ILogger;
import gameEngine.agents.Logger.Massages.Massage;
import gameEngine.agents.Logger.Massages.MassageFactory;
import gameEngine.agents.Logger.Massages.MassageEnum.Massage_Type;
import gameEngine.agents.observationSystem.samples.Sample;
import gameEngine.game.TurnBasedScoredGame;

/**
 * a proxy for agent, this one extends agent capabilities by logging the turn
 * @author alon
 *
 */

public class LoggedAgent implements Agent{
	
	private Agent agent;
	private ILogger log;
	private Massage massage;
	private TurnBasedScoredGame game;
	
	public LoggedAgent(ILogger log, TurnBasedScoredGame game, Massage_Type massageType) {
		super();
		this.log = log;
		this.game=game;
		this.massage = MassageFactory.create(Massage_Type.CSV,this.game);
	}

	public int chooseNextPlayer() {
		return agent.chooseNextPlayer();
	}
	/**
	 * extends BasicAgent functionality and writes a log 
	 */
	public double play() {
		double score=agent.play();
		massage.setContent(""+getID(), Double.toString(score));
		log.log(massage.getMassage());
		return score;
	}
	
	/**
	 * returns the Agent used by this logged one 
	 * @return Agent
	 */
	public Agent getAgent() {
		return agent;
	}

	/**
	 * sets the current agent
	 * @param agent
	 */
	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	public int getID() {
		return agent.getID();
	}
	/**
	 * returns used logger
	 * @return
	 */
	public ILogger getLog() {
		return log;
	}

	/**
	 * sets logger
	 * @param log
	 */
	public void setLog(ILogger log) {
		this.log = log;
	}

	/**
	 * returns the massage in use
	 * @return Massage
	 */
	public Massage getMassage() {
		return massage;
	}

	/**
	 * sets Massage in use
	 * @param massage
	 */
	public void setMassage(Massage massage) {
		this.massage = massage;
	}

	public double getCompetence() {
		return agent.getCompetence();
	}

	public void setCompetence(double competence){
		agent.setCompetence(competence);
	}
	
	public double getEpsilonGreedy() {
		return agent.getEpsilonGreedy();
	}
	
	public void setEpsilonGreedy(double epsilon){
		agent.setEpsilonGreedy(epsilon);
	}

	public void analyzeSample(Sample s) {
		agent.analyzeSample(s);
	}
	
	public LoggedAgent clone(){
		return new LoggedAgent(log, game,Massage_Type.CSV);		
	}
	
	public void initClonesModel(ArrayList<Agent> agents){
		agent.initClonesModel(agents);
	}

}
